/*************************************************************************
 *                                                                       *
 * This file is part of the FreeMAPs distribution.  For full copyright   *
 * information, see COPYRIGHT and COPYING.LESSER.                        *
 *                                                                       *
 * Author:           sqbang                                              *
 * Email:            sqbang@ustc.edu                                     *
 * Date:             2013.11.19                                          *
 *                                                                       *
 *************************************************************************/

namespace FreeMAPs
{

inline void
MeshGroup::insert_node_group (
    const NodeGroup& node_group)
{
    const std::string& ng_name = node_group.get_group_name();
    FREEMAPS_ASSERT (!ng_name.empty());

    const int ng_id = d_boundary_names.size();
    d_boundary_names.insert (ng_name, ng_id);

    d_node_groups.insert (std::make_pair (ng_name, node_group));
}


inline void
MeshGroup::insert_node_to_node_group (
    const std::string& group_name,
    const int node_id)
{
    std::map<std::string, NodeGroup>::iterator find_group = d_node_groups.find (group_name);
    FREEMAPS_ASSERT (find_group != d_node_groups.end());
    find_group->second.insert_node (node_id);
}

#if 0
inline void
MeshGroup::insert_side_group (
    const SideGroup& side_group)
{
    const std::string& sg_name = side_group.get_group_name();
    FREEMAPS_ASSERT (!sg_name.empty());

    const int sg_id = d_boundary_names.size();
    //std::cout << "sg_id = " << sg_id << ", sg_name = " << sg_name << std::endl;

    d_boundary_names.insert (sg_name, sg_id);

    d_side_groups.insert (std::make_pair (sg_name, side_group));
}


inline void
MeshGroup::insert_edge_group (
    const EdgeGroup& edge_group)
{
    const std::string& eg_name = edge_group.get_group_name();
    FREEMAPS_ASSERT (!eg_name.empty());

    const int eg_id = d_boundary_names.size();
    d_boundary_names.insert (eg_name, eg_id);

    d_edge_groups.insert (std::make_pair (eg_name, edge_group));
}


inline void
MeshGroup::insert_elem_group (
    const ElemGroup& elem_group)
{
    FREEMAPS_ASSERT (!elem_group.get_group_name().empty());

    d_elem_groups.insert (std::make_pair (elem_group.get_group_name(), elem_group));
    d_subdomain_names.insert (elem_group.get_group_name(), d_elem_groups.size());
    d_boundary_names.insert (elem_group.get_group_name(), d_boundary_names.size());
}


inline void
MeshGroup::insert_elem_to_elem_group (
    const std::string& subdomain_name,
    const int elem_id)
{
    std::map<std::string, ElemGroup>::iterator find_group = d_elem_groups.find (subdomain_name);
    FREEMAPS_ASSERT (find_group != d_elem_groups.end());
    find_group->second.insert_elem_id (elem_id);
}
#endif

inline const std::map<std::string, NodeGroup>&
MeshGroup::get_node_groups() const
{
    return d_node_groups;
}

#if 0
inline const std::map<std::string, SideGroup>&
MeshGroup::get_side_groups() const
{
    return d_side_groups;
}


inline const std::map<std::string, EdgeGroup>&
MeshGroup::get_edge_groups() const
{
    return d_edge_groups;
}


inline const std::map<std::string, ElemGroup>&
MeshGroup::get_elem_groups() const
{
    return d_elem_groups;
}


inline int
MeshGroup::get_subdomain_id (
    const std::string& subdomain_name) const
{
    return d_subdomain_names.get_value (subdomain_name);
}


inline const Bimap<std::string, int>&
MeshGroup::get_subdomain_names() const
{
    return d_subdomain_names;
}


inline bool
MeshGroup::has_node_group(
    const std::string& group_name) const
{
    return (d_node_groups.count (group_name) > 0);
}


inline bool
MeshGroup::has_side_group(
    const std::string& group_name) const
{
    return (d_side_groups.count (group_name) > 0);
}


inline bool
MeshGroup::has_edge_group(
    const std::string& group_name) const
{
    return (d_edge_groups.count (group_name) > 0);
}


inline bool
MeshGroup::has_elem_group(
    const std::string& group_name) const
{
    return (d_elem_groups.count (group_name) > 0);
}


inline int
MeshGroup::get_boundary_id (
    const std::string& bd_name) const
{
    return d_boundary_names.get_value (bd_name);
}
#endif
}
